package com.huike.web.controller.clues;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huike.clues.domain.TbActivity;
import com.huike.clues.domain.dto.TbActivityDTO;
import com.huike.clues.domain.dto.mydto.ActivityQueryDTO;
import com.huike.clues.service.TbActivityService;
import com.huike.common.annotation.RepeatSubmit;
import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.core.page.TableDataInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 活动管理Controller
 *
 * @date 2023-04-01
 */
@Slf4j
@RestController
@RequestMapping("/clues/activity")
public class TbActivityController extends BaseController {

    @Autowired
    private TbActivityService tbActivityService;

    /**
     * 新增活动管理
     *
     * @param tbActivityDTO
     * @return
     */
    @RepeatSubmit
    @PostMapping
    public AjaxResult addTbActivity(@RequestBody TbActivityDTO tbActivityDTO) {
        log.info("新增活动管理:{}", tbActivityDTO);
        return toAjax(tbActivityService.addTbActivity(tbActivityDTO));
    }


    /**
     * 修改活动管理
     */
    @PutMapping
    public AjaxResult updateTbActivity(@RequestBody TbActivityDTO tbActivityDTO) {
        log.info("修改活动管理:{}", tbActivityDTO);
        return toAjax(tbActivityService.updateTbActivity(tbActivityDTO));
    }


    /**
     * 分页查询活动管理信息
     */
    @GetMapping("/list")
    public TableDataInfo list(ActivityQueryDTO activityQueryDTO) {

        Map<String, Object> resultMap = tbActivityService.selectTbActivityList(activityQueryDTO);
        Page<TbActivity> page = (Page<TbActivity>) resultMap.get("page");
        Map<String, Object> paramMap = (Map<String, Object>) resultMap.get("paramMap");
        // 封装分页数据
        TableDataInfo tbActivityTableDataInfo = getDataTable(page.getRecords(), paramMap);

        return tbActivityTableDataInfo;
    }

    /**
     * 获取状态为为2的渠道活动列表
     *
     * @return
     */
    @GetMapping("/listselect/{channel}")
    public AjaxResult selectTbActivityByStatus(@PathVariable Long channel) {
        List<TbActivity> tbActivity = tbActivityService.selectTbActivityByStatus(channel);
        return AjaxResult.success(tbActivity);
    }


    /**
     * 删除活动管理
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/{ids}")
    public AjaxResult delectTbActivity(@PathVariable Long[] ids) {
        return toAjax(tbActivityService.delectTbActivity(ids));
    }

    /**
     * 查询活动管理详细信息
     *
     * @return
     */
    @GetMapping("/{id}")
    public AjaxResult selectTbActivity(@PathVariable Long id) {
        TbActivity tbActivity = tbActivityService.selectTbActivity(id);
        return AjaxResult.success(tbActivity);
    }
}
